package com.coolwen.controller;

import com.coolwen.service.councilor.CouncilorService;
import com.coolwen.service.expert.ExpertService;
import com.coolwen.service.student.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Nieyu on 2016/10/20.
 */
@Controller
@RequestMapping("/course")
public class CourseController {

    @Autowired
    CouncilorService councilorService;

    @Autowired
    ExpertService expertService;

    @Autowired
    StudentService studentService;

    /**
     *查看详细督导、专家评教课程信息
     * @return
     */
    @RequestMapping(value = "/councilor_info", method = RequestMethod.GET)
    public String councilorInfo(Model model, String grade, String department, String major, String course,HttpServletRequest request) {

        model.addAttribute("g", grade);
        model.addAttribute("d", department);
        model.addAttribute("m", major);
        model.addAttribute("course", course);

        if (department != null && !department.equals("")) {
            String subDepartment = request.getParameter("department");
            department = subDepartment.substring(0, 2);
        }

        model.addAttribute("councilors", councilorService.selectCouncilorCourseInfo(grade, department, major, course));
        model.addAttribute("experts", expertService.selectExpertCourseInfo(grade, department, major, course));

        return "page/courseInfo";

    }

    /**
     *查看详细学生、督导、专家评教课程信息
     * @return
     */
    @RequestMapping(value = "/totalCourseInfo", method = RequestMethod.GET)
    public String totalCourseInfo(Model model, String grade, String department, String major, String course) {

        model.addAttribute("grade", grade);
        model.addAttribute("department", department);
        model.addAttribute("major", major);
        model.addAttribute("course", course);

        model.addAttribute("councilors", councilorService.selectAllCouncilorCourseInfo(grade, department, major, course));
        model.addAttribute("experts", expertService.selectAllExpertCourseInfo(grade, department, major, course));
        model.addAttribute("students", studentService.selectStudentCourseInfo(grade, department, major, course));

        return "page/totalCourseInfo";

    }

    /**
     *查看详细学生评教课程信息
     * @return
     */
    @RequestMapping(value = "/studentInfo", method = RequestMethod.GET)
    public String studentInfo(Model model, String grade, String department, String major, String course) {

        model.addAttribute("grade", grade);
        model.addAttribute("department", department);
        model.addAttribute("major", major);
        model.addAttribute("course", course);

        model.addAttribute("students", studentService.selectStudentOneCourseInfo(grade, department, major, course));

        return "page/studentCourseInfo";

    }
}
